<template>
  <div class="home">
            <table border="1" cellspacing="5" cellpadding="20">
                <tr>
                    <th>项目名</th>
                    <th>工程名</th>
                    <th>git地址</th>
                    <th>操作1</th>
                    <th>操作2</th>
                </tr>
                <tr v-for="(item,index) in list" :key="index">
                    <td>{{item.name}}</td>
                    <td>{{item.projectName }}</td>
                    <td>{{item.gitAddress}}</td>
                    <td @click="buildAndPush(item.projectName)">构建并发布</td>
                    <td @click="deleteItem(item.projectName)">删除</td>
                </tr>
            </table>

      <button  @click="deleteItem2">删除</button>
  </div>

</template>

<script>
  import axios from 'axios'
    // @ is an alias to /src
    export default {
        name: 'AddForm',
        data(){
          return{
            list:[]
          }
        },
        methods:{
            submit(){
              const obj = {name:this.name, gitAddress:this.gitAddress, projectName:this.projectName}
                console.log(obj)
                axios.post('http://128.hktqa.cn:3000/api/doAdd', obj)

            },
            async getData(){
                const result= await axios.get('http://128.hktqa.cn:3000/api/getList')
                const {code, data} = result.data||{}
                if(code==0){
                    this.list = data
                }
            },
            async deleteItem(projectName){
                const result= await axios.post('http://128.hktqa.cn:3000/api/deleteItem',{projectName})
                const {code, data} = result.data||{}
                if(code==0){
                    this.list = data
                }
            },
            async deleteItem2(projectName){
                const result= await axios.post('http://128.hktqa.cn:3000/api/test2',{projectName});
            },

            async buildAndPush(projectName){
                const result= await axios.post('http://128.hktqa.cn:3000/api/build',{projectName})
                const {code, data} = result.data||{}
                if(code==0){
                    this.list = data
                }
            },
        }
        ,
        mounted(){
            this.getData()
        },
    }
</script>
